package com.interview.javabase.algorithm.hand.可重入锁;

/**
 * 可重入锁测试
 *
 * @author zhangshguang
 * @date 2020/07/27
 */
public class ReentrantDemo {

    public void test() {
        synchronized (this) {
            System.out.println("测试11");
            synchronized (this) {
                System.out.println("测试22");

                int index = 1;
                while (true) {
                    synchronized (this) {
                        System.out.println("第" + (++index) + "次获取锁，这个锁是：" + this);
                    }
                    if (index == 10) {
                        break;
                    }
                }
            }
        }
    }

    public static void main(String[] args) {
        ReentrantDemo reentrantDemo = new ReentrantDemo();
        reentrantDemo.test();

    }
}
